<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Module: ActiveScaffold::Constraints</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Module</strong></td>
          <td class="class-name-in-header">ActiveScaffold::Constraints</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../files/vendor/plugins/active_scaffold/lib/constraints_rb.html">
                vendor/plugins/active_scaffold/lib/constraints.rb
                </a>
        <br />
            </td>
        </tr>

        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">



   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000164">active_scaffold_constraints</a>&nbsp;&nbsp;
      <a href="#M000169">apply_constraints_to_record</a>&nbsp;&nbsp;
      <a href="#M000167">condition_from_association_constraint</a>&nbsp;&nbsp;
      <a href="#M000166">conditions_from_constraints</a>&nbsp;&nbsp;
      <a href="#M000168">constraint_error</a>&nbsp;&nbsp;
      <a href="#M000163">included</a>&nbsp;&nbsp;
      <a href="#M000165">register_constraints_with_action_columns</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Class methods</h3>

      <div id="method-M000163" class="method-detail">
        <a name="M000163"></a>

        <div class="method-heading">
          <a href="#M000163" class="method-signature">
          <span class="method-name">included</span><span class="method-args">(base)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000163-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000163-source">
<pre>
   <span class="ruby-comment cmt"># File vendor/plugins/active_scaffold/lib/constraints.rb, line 3</span>
3:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">included</span>(<span class="ruby-identifier">base</span>)
4:       <span class="ruby-identifier">base</span>.<span class="ruby-identifier">module_eval</span> <span class="ruby-keyword kw">do</span>
5:         <span class="ruby-identifier">before_filter</span> <span class="ruby-identifier">:register_constraints_with_action_columns</span>
6:       <span class="ruby-keyword kw">end</span>
7:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Protected Instance methods</h3>

      <div id="method-M000164" class="method-detail">
        <a name="M000164"></a>

        <div class="method-heading">
          <a href="#M000164" class="method-signature">
          <span class="method-name">active_scaffold_constraints</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the current constraints
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000164-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000164-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/active_scaffold/lib/constraints.rb, line 12</span>
12:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">active_scaffold_constraints</span>
13:       <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">active_scaffold_session_storage</span>[<span class="ruby-identifier">:constraints</span>] <span class="ruby-operator">||</span> {}
14:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000169" class="method-detail">
        <a name="M000169"></a>

        <div class="method-heading">
          <a href="#M000169" class="method-signature">
          <span class="method-name">apply_constraints_to_record</span><span class="method-args">(record, options = {})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Applies constraints to the given record.
</p>
<p>
Searches through the known columns for association columns. If the given
constraint is an association, it assumes that the constraint value is an
id. It then does a association.klass.find with the value and adds the
associated object to the record.
</p>
<p>
For some operations <a href="../ActiveRecord.html">ActiveRecord</a> will
automatically update the database. That&#8216;s not always ok. If it
<b>is</b> ok (e.g. you&#8216;re in a transaction), then set :allow_autosave
to true.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000169-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000169-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_scaffold/lib/constraints.rb, line 131</span>
131:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">apply_constraints_to_record</span>(<span class="ruby-identifier">record</span>, <span class="ruby-identifier">options</span> = {})
132:       <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:allow_autosave</span>] = <span class="ruby-keyword kw">false</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:allow_autosave</span>].<span class="ruby-identifier">nil?</span>
133: 
134:       <span class="ruby-identifier">active_scaffold_constraints</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">k</span>, <span class="ruby-identifier">v</span><span class="ruby-operator">|</span>
135:         <span class="ruby-identifier">column</span> = <span class="ruby-identifier">active_scaffold_config</span>.<span class="ruby-identifier">columns</span>[<span class="ruby-identifier">k</span>]
136:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">column</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">column</span>.<span class="ruby-identifier">association</span>
137:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">v</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">Hash</span> <span class="ruby-comment cmt"># reverse of a through association ... we need to set the far association</span>
138:             <span class="ruby-comment cmt"># example</span>
139:             <span class="ruby-comment cmt">#   data model: Park -&gt; Den -&gt; Bear</span>
140:             <span class="ruby-comment cmt">#   constraint: :den =&gt; {:park =&gt; 5}</span>
141:             <span class="ruby-comment cmt">#   remote_klass: Park</span>
142:             <span class="ruby-identifier">remote_klass</span> = <span class="ruby-identifier">column</span>.<span class="ruby-identifier">association</span>.<span class="ruby-identifier">klass</span>.<span class="ruby-identifier">reflect_on_association</span>(<span class="ruby-identifier">v</span>.<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">first</span>).<span class="ruby-identifier">klass</span>
143:             <span class="ruby-identifier">first_associated</span> = <span class="ruby-identifier">record</span>.<span class="ruby-identifier">send</span>(<span class="ruby-node">&quot;#{k}&quot;</span>)
144:             <span class="ruby-identifier">first_associated</span>.<span class="ruby-identifier">send</span>(<span class="ruby-node">&quot;#{v.keys.first}=&quot;</span>, <span class="ruby-identifier">remote_klass</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">v</span>.<span class="ruby-identifier">values</span>.<span class="ruby-identifier">first</span>)) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">first_associated</span>
145:           <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">column</span>.<span class="ruby-identifier">plural_association?</span>
146:             <span class="ruby-identifier">record</span>.<span class="ruby-identifier">send</span>(<span class="ruby-node">&quot;#{k}&quot;</span>).<span class="ruby-identifier">send</span>(<span class="ruby-identifier">:&lt;&lt;</span>, <span class="ruby-identifier">column</span>.<span class="ruby-identifier">association</span>.<span class="ruby-identifier">klass</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">v</span>))
147:           <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">column</span>.<span class="ruby-identifier">association</span>.<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:polymorphic</span>]
148:             <span class="ruby-identifier">record</span>.<span class="ruby-identifier">send</span>(<span class="ruby-node">&quot;#{k}=&quot;</span>, <span class="ruby-identifier">params</span>[<span class="ruby-identifier">:parent_model</span>].<span class="ruby-identifier">constantize</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">v</span>))
149:           <span class="ruby-keyword kw">else</span> <span class="ruby-comment cmt"># regular singular association</span>
150:             <span class="ruby-identifier">record</span>.<span class="ruby-identifier">send</span>(<span class="ruby-node">&quot;#{k}=&quot;</span>, <span class="ruby-identifier">column</span>.<span class="ruby-identifier">association</span>.<span class="ruby-identifier">klass</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">v</span>))
151: 
152:             <span class="ruby-comment cmt"># setting the belongs_to side of a has_one isn't safe. if the has_one was already</span>
153:             <span class="ruby-comment cmt"># specified, rails won't automatically clear out the previous associated record.</span>
154:             <span class="ruby-comment cmt">#</span>
155:             <span class="ruby-comment cmt"># note that we can't take the extra step to correct this unless we're permitted to</span>
156:             <span class="ruby-comment cmt"># run operations where activerecord auto-saves the object.</span>
157:             <span class="ruby-identifier">reverse</span> = <span class="ruby-identifier">column</span>.<span class="ruby-identifier">association</span>.<span class="ruby-identifier">klass</span>.<span class="ruby-identifier">reflect_on_association</span>(<span class="ruby-identifier">column</span>.<span class="ruby-identifier">association</span>.<span class="ruby-identifier">reverse</span>)
158:             <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">reverse</span>.<span class="ruby-identifier">macro</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">:has_one</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:allow_autosave</span>]
159:               <span class="ruby-identifier">record</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">k</span>).<span class="ruby-identifier">send</span>(<span class="ruby-node">&quot;#{column.association.reverse}=&quot;</span>, <span class="ruby-identifier">record</span>)
160:             <span class="ruby-keyword kw">end</span>
161:           <span class="ruby-keyword kw">end</span>
162:         <span class="ruby-keyword kw">else</span>
163:           <span class="ruby-identifier">record</span>.<span class="ruby-identifier">send</span>(<span class="ruby-node">&quot;#{k}=&quot;</span>, <span class="ruby-identifier">v</span>)
164:         <span class="ruby-keyword kw">end</span>
165:       <span class="ruby-keyword kw">end</span>
166:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000167" class="method-detail">
        <a name="M000167"></a>

        <div class="method-heading">
          <a href="#M000167" class="method-signature">
          <span class="method-name">condition_from_association_constraint</span><span class="method-args">(association, value)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
We do NOT want to use .search_sql. If anything, search_sql will refer to a
human-searchable value on the associated record.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000167-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000167-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_scaffold/lib/constraints.rb, line 82</span>
 82:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">condition_from_association_constraint</span>(<span class="ruby-identifier">association</span>, <span class="ruby-identifier">value</span>)
 83:       <span class="ruby-comment cmt"># when the reverse association is a :belongs_to, the id for the associated object only exists as</span>
 84:       <span class="ruby-comment cmt"># the primary_key on the other table. so for :has_one and :has_many (when the reverse is :belongs_to),</span>
 85:       <span class="ruby-comment cmt"># we have to use the other model's primary_key.</span>
 86:       <span class="ruby-comment cmt">#</span>
 87:       <span class="ruby-comment cmt"># please see the relevant tests for concrete examples.</span>
 88:       <span class="ruby-identifier">field</span> = <span class="ruby-keyword kw">if</span> [<span class="ruby-identifier">:has_one</span>, <span class="ruby-identifier">:has_many</span>].<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">association</span>.<span class="ruby-identifier">macro</span>)
 89:         <span class="ruby-identifier">association</span>.<span class="ruby-identifier">klass</span>.<span class="ruby-identifier">primary_key</span>
 90:       <span class="ruby-keyword kw">else</span>
 91:         <span class="ruby-identifier">association</span>.<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:association_foreign_key</span>] <span class="ruby-operator">||</span> <span class="ruby-identifier">association</span>.<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:foreign_key</span>] <span class="ruby-operator">||</span> <span class="ruby-identifier">association</span>.<span class="ruby-identifier">association_foreign_key</span>
 92:       <span class="ruby-keyword kw">end</span>
 93: 
 94:       <span class="ruby-identifier">table</span> = <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">association</span>.<span class="ruby-identifier">macro</span>
 95:         <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:has_and_belongs_to_many</span>
 96:         <span class="ruby-identifier">association</span>.<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:join_table</span>]
 97: 
 98:         <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:belongs_to</span>
 99:         <span class="ruby-identifier">active_scaffold_config</span>.<span class="ruby-identifier">model</span>.<span class="ruby-identifier">table_name</span>
100: 
101:         <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:has_many</span>
102:         <span class="ruby-identifier">association</span>.<span class="ruby-identifier">table_name</span>
103: 
104:         <span class="ruby-keyword kw">else</span>
105:         <span class="ruby-identifier">association</span>.<span class="ruby-identifier">table_name</span>
106:       <span class="ruby-keyword kw">end</span>
107: 
108:       <span class="ruby-identifier">condition</span> = <span class="ruby-identifier">constraint_condition_for</span>(<span class="ruby-node">&quot;#{table}.#{field}&quot;</span>, <span class="ruby-identifier">value</span>)
109:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">association</span>.<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:polymorphic</span>]
110:         <span class="ruby-identifier">condition</span> = <span class="ruby-identifier">merge_conditions</span>(
111:           <span class="ruby-identifier">condition</span>,
112:           <span class="ruby-identifier">constraint_condition_for</span>(<span class="ruby-node">&quot;#{table}.#{association.name}_type&quot;</span>, <span class="ruby-identifier">params</span>[<span class="ruby-identifier">:parent_model</span>].<span class="ruby-identifier">to_s</span>)
113:         )
114:       <span class="ruby-keyword kw">end</span>
115: 
116:       <span class="ruby-identifier">condition</span>
117:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000166" class="method-detail">
        <a name="M000166"></a>

        <div class="method-heading">
          <a href="#M000166" class="method-signature">
          <span class="method-name">conditions_from_constraints</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns search conditions based on the current scaffold constraints.
</p>
<p>
Supports constraints based on either a column name (in which case it checks
for an association or just uses the search_sql) or a database field name.
</p>
<p>
All of this work is primarily to support nested scaffolds in a manner
generally useful for other embedded scaffolds.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000166-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000166-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/active_scaffold/lib/constraints.rb, line 40</span>
40:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">conditions_from_constraints</span>
41:       <span class="ruby-identifier">conditions</span> = <span class="ruby-keyword kw">nil</span>
42:       <span class="ruby-identifier">active_scaffold_constraints</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">k</span>, <span class="ruby-identifier">v</span><span class="ruby-operator">|</span>
43:         <span class="ruby-identifier">column</span> = <span class="ruby-identifier">active_scaffold_config</span>.<span class="ruby-identifier">columns</span>[<span class="ruby-identifier">k</span>]
44:         <span class="ruby-identifier">constraint_condition</span> = <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">column</span>
45:           <span class="ruby-comment cmt"># Assume this is a multi-level association constraint.</span>
46:           <span class="ruby-comment cmt"># example:</span>
47:           <span class="ruby-comment cmt">#   data model: Park -&gt; Den -&gt; Bear</span>
48:           <span class="ruby-comment cmt">#   constraint: :den =&gt; {:park =&gt; 5}</span>
49:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">v</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">Hash</span>
50:             <span class="ruby-identifier">far_association</span> = <span class="ruby-identifier">column</span>.<span class="ruby-identifier">association</span>.<span class="ruby-identifier">klass</span>.<span class="ruby-identifier">reflect_on_association</span>(<span class="ruby-identifier">v</span>.<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">first</span>)
51:             <span class="ruby-identifier">field</span> = <span class="ruby-identifier">far_association</span>.<span class="ruby-identifier">klass</span>.<span class="ruby-identifier">primary_key</span>
52:             <span class="ruby-identifier">table</span> = <span class="ruby-identifier">far_association</span>.<span class="ruby-identifier">table_name</span>
53: 
54:             <span class="ruby-identifier">active_scaffold_joins</span>.<span class="ruby-identifier">concat</span>([{<span class="ruby-identifier">k</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">v</span>.<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">first</span>}]) <span class="ruby-comment cmt"># e.g. {:den =&gt; :park}</span>
55:             <span class="ruby-identifier">constraint_condition_for</span>(<span class="ruby-node">&quot;#{table}.#{field}&quot;</span>, <span class="ruby-identifier">v</span>.<span class="ruby-identifier">values</span>.<span class="ruby-identifier">first</span>)
56: 
57:           <span class="ruby-comment cmt"># association column constraint</span>
58:           <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">column</span>.<span class="ruby-identifier">association</span>
59:             <span class="ruby-identifier">active_scaffold_joins</span>.<span class="ruby-identifier">concat</span> <span class="ruby-identifier">column</span>.<span class="ruby-identifier">includes</span>
60:             <span class="ruby-identifier">condition_from_association_constraint</span>(<span class="ruby-identifier">column</span>.<span class="ruby-identifier">association</span>, <span class="ruby-identifier">v</span>)
61: 
62:           <span class="ruby-comment cmt"># regular column constraints</span>
63:           <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">column</span>.<span class="ruby-identifier">searchable?</span>
64:             <span class="ruby-identifier">active_scaffold_joins</span>.<span class="ruby-identifier">concat</span> <span class="ruby-identifier">column</span>.<span class="ruby-identifier">includes</span>
65:             <span class="ruby-identifier">constraint_condition_for</span>(<span class="ruby-identifier">column</span>.<span class="ruby-identifier">search_sql</span>, <span class="ruby-identifier">v</span>)
66:           <span class="ruby-keyword kw">end</span>
67:         <span class="ruby-comment cmt"># unknown-to-activescaffold-but-real-database-column constraint</span>
68:         <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">active_scaffold_config</span>.<span class="ruby-identifier">model</span>.<span class="ruby-identifier">column_names</span>.<span class="ruby-identifier">include?</span> <span class="ruby-identifier">k</span>.<span class="ruby-identifier">to_s</span>
69:           <span class="ruby-identifier">constraint_condition_for</span>(<span class="ruby-identifier">k</span>.<span class="ruby-identifier">to_s</span>, <span class="ruby-identifier">v</span>)
70:         <span class="ruby-keyword kw">else</span>
71:           <span class="ruby-identifier">raise</span> <span class="ruby-constant">ActiveScaffold</span><span class="ruby-operator">::</span><span class="ruby-constant">MalformedConstraint</span>, <span class="ruby-identifier">constraint_error</span>(<span class="ruby-identifier">active_scaffold_config</span>.<span class="ruby-identifier">model</span>, <span class="ruby-identifier">k</span>), <span class="ruby-identifier">caller</span>
72:         <span class="ruby-keyword kw">end</span>
73: 
74:         <span class="ruby-identifier">conditions</span> = <span class="ruby-identifier">merge_conditions</span>(<span class="ruby-identifier">conditions</span>, <span class="ruby-identifier">constraint_condition</span>)
75:       <span class="ruby-keyword kw">end</span>
76: 
77:       <span class="ruby-identifier">conditions</span>
78:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000168" class="method-detail">
        <a name="M000168"></a>

        <div class="method-heading">
          <a href="#M000168" class="method-signature">
          <span class="method-name">constraint_error</span><span class="method-args">(klass, column_name)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000168-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000168-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_scaffold/lib/constraints.rb, line 119</span>
119:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">constraint_error</span>(<span class="ruby-identifier">klass</span>, <span class="ruby-identifier">column_name</span>)
120:       <span class="ruby-node">&quot;Malformed constraint `#{klass}##{column_name}'. If it's a legitimate column, and you are using a nested scaffold, please specify or double-check the reverse association name.&quot;</span>
121:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000165" class="method-detail">
        <a name="M000165"></a>

        <div class="method-heading">
          <a href="#M000165" class="method-signature">
          <span class="method-name">register_constraints_with_action_columns</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
For each enabled action, adds the constrained columns to the ActionColumns
object (if it exists). This lets the ActionColumns object skip constrained
columns.
</p>
<p>
If the constraint value is a Hash, then we assume the constraint is a
multi-level association constraint (the reverse of a has_many :through) and
we do NOT register the constraint column.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000165-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000165-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/active_scaffold/lib/constraints.rb, line 20</span>
20:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">register_constraints_with_action_columns</span>
21:       <span class="ruby-identifier">constrained_fields</span> = <span class="ruby-identifier">active_scaffold_constraints</span>.<span class="ruby-identifier">reject</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">k</span>, <span class="ruby-identifier">v</span><span class="ruby-operator">|</span> <span class="ruby-identifier">v</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">Hash</span>}.<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">collect</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">k</span><span class="ruby-operator">|</span> <span class="ruby-identifier">k</span>.<span class="ruby-identifier">to_sym</span>}
22: 
23:       <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">uses_active_scaffold?</span>
24:         <span class="ruby-comment cmt"># we actually want to do this whether constrained_fields exist or not, so that we can reset the array when they don't</span>
25:         <span class="ruby-identifier">active_scaffold_config</span>.<span class="ruby-identifier">actions</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">action_name</span><span class="ruby-operator">|</span>
26:           <span class="ruby-identifier">action</span> = <span class="ruby-identifier">active_scaffold_config</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">action_name</span>)
27:           <span class="ruby-keyword kw">next</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">action</span>.<span class="ruby-identifier">respond_to?</span> <span class="ruby-identifier">:columns</span>
28:           <span class="ruby-identifier">action</span>.<span class="ruby-identifier">columns</span>.<span class="ruby-identifier">constraint_columns</span> = <span class="ruby-identifier">constrained_fields</span>
29:         <span class="ruby-keyword kw">end</span>
30:       <span class="ruby-keyword kw">end</span>
31:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>